﻿using CSRedis;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;

namespace AIStudio.ConSole.Redis.Ch03
{
    /********************************************************************************************************
    # <start id="simple-pipeline-notrans"/>
    >>> def notrans():
    ...     print conn.incr('notrans:')                     #A
    ...     time.sleep(.1)                                  #B
    ...     conn.incr('notrans:', -1)                       #C
    ...
    >>> if 1:
    ...     for i in xrange(3) :                             #D
    ...         threading.Thread(target=notrans).start()    #D
    ...     time.sleep(.5)                                  #E
    ...
    1                                                       #F
    2                                                       #F
    3                                                       #F
    # <end id="simple-pipeline-notrans"/>
    *********************************************************************************************************/
    class TestNotrans
    {
        CSRedisClient _conn;
        public TestNotrans()
        {
            _conn = new CSRedis.CSRedisClient("127.0.0.1:6379,defaultDatabase=14,poolsize=500,ssl=false,writeBuffer=10240");
        }
        public void Notrans()
        {
            Console.WriteLine(_conn.IncrBy("notrans:"));
            Thread.Sleep(100);
            _conn.IncrBy("notrans:", -1);
        }

        public void Test()
        {
            for (int i = 0; i < 3; i++)
            {
                Thread thread = new Thread(new ThreadStart(Notrans));
                thread.Start();
            }
            Thread.Sleep(500);
        }
    }
}
